package DailyPractice.Day7;

import java.util.Scanner;

/**
 * @author lumin
 * @date 2022/04/25 11:32
 **/
public class fibNum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        System.out.println(Fib(num));
    }

    private static int Fib(int num) {
        int i = 0;
        int MinNum = Integer.MAX_VALUE;
        while(fib(i) < num){
            MinNum = Math.min(MinNum , num - fib(i));
            i++;
        }
        MinNum = Math.min(MinNum , Math.abs(num - fib(i)));
        return MinNum;
    }

    public static int fib(int n) {
        if (n < 2) {
            return n;
        }
        int p = 0, q = 0, r = 1;
        for (int i = 2; i <= n; ++i) {
            p = q;
            q = r;
            r = p + q;
        }
        return r;
    }

}